package com.example.shop_car_2208.mvvmdemo

import androidx.lifecycle.MutableLiveData
import com.example.shop_car_2208.entity.ParamLogin
import com.example.shop_car_2208.entity.UserEntityResult
import com.example.shop_car_2208.net.ApiService
import com.example.shop_car_2208.net.RetrofitUtils
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

class LoginRepo {
    fun login(param:ParamLogin,loginSuccess:MutableLiveData<UserEntityResult>,loginFail:MutableLiveData<String>){
        val apiService = RetrofitUtils.getRetrofit().create(ApiService::class.java)
        apiService.login1(param)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.computation())
            .subscribe(object: Observer<UserEntityResult>{
                override fun onSubscribe(d: Disposable) {
                }

                override fun onError(e: Throwable) {
                    loginFail.value = e.message
                }

                override fun onComplete() {

                }

                override fun onNext(t: UserEntityResult) {
                    loginSuccess.value = t
                }
            })
    }
}